package com.jcfriends.common.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class AppendModelMapInterceptor extends HandlerInterceptorAdapter {

	@Value("#{jcfriendProps['jc.array.year']}")
	String yearListStr;
	
	@Value("#{jcfriendProps['jc.array.month']}")
	String monthListStr;
	
	@Value("#{jcfriendProps['jc.array.date']}")
	String dateListStr;

	@Value("#{jcfriendProps['jc.config.web.contextRoot']}")
	String contextRoot;
	
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception{
		
		return true;
	}

	public void postHandle(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, Object obj, ModelAndView mav)throws Exception{
	

        ModelMap map = new ModelMap();
        
        map.addAttribute("CONTEXT_ROOT", contextRoot);				//CONTEXT_ROOT 지정

        map.addAttribute("yearList", yearListStr.split(","));		//년도 리스트
        map.addAttribute("monthList", monthListStr.split(","));		//월 리스트
        map.addAttribute("dateList", dateListStr.split(","));		//일 리스트        
        
        if( mav == null ) mav = new ModelAndView();
        mav.getModelMap().addAllAttributes( map );
	}
	
	public void afterCompletion(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, Object obj, Exception exception)throws Exception{
	
	} 
}
